/**
 * 
 */
package cn.ipenta.jkb.web;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.ipenta.jkb.JkbWebException;
import cn.ipenta.jkb.entity.TxInfo;
import cn.ipenta.jkb.service.HealerService;
import cn.ipenta.jkb.utils.JsonMapper;
import cn.ipenta.jkb.web.vo.PayVo;
import net.sf.cglib.beans.BeanCopier;

/** 
* @ClassName: HealerController 
* @Description: TODO
* @author ipenta
* @date 2017年4月16日 下午9:55:16 
*  
*/
@Controller
public class HealerController {
	
	final BeanCopier copier = BeanCopier.create(PayVo.class, TxInfo.class, false);
	

	@Autowired
	HealerService healerService;
	
	@PostMapping("/api/healer/pay")
	public @ResponseBody Map<String, Object> pay(@RequestBody PayVo payVo) throws JkbWebException {
		TxInfo txInfo = new TxInfo();
		copier.copy(payVo, txInfo, null);
		Boolean isPaid = healerService.createPay(txInfo);
	
		return JsonMapper.success(isPaid);
	}
	
	@GetMapping("/api/healer/apply/list")
	public @ResponseBody Map<String, Object> findApplyList(@RequestParam String id) throws JkbWebException {
		List<TxInfo> txInfos = healerService.findApplyRecordById(id);
		return JsonMapper.success(txInfos);
	}

	@GetMapping("/api/healer/pay/list")
	public @ResponseBody Map<String, Object> findPayList(@RequestParam String id) throws JkbWebException {
		List<TxInfo> txInfos = healerService.findPayRecordById(id);
		return JsonMapper.success(txInfos);
	}

}
